// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import dialogControl from "./dialogControl";

const {ccclass, property} = cc._decorator;

// 建立角色映射
// let roleMap = new Map()
// roleMap.set(1, { name: '勇者', url:'role/hero' })
// roleMap.set(2, { name: '魔王', url:'role/npc' })

// import { origin, expressionMap } from "./dataSet";

// 任务对话控制脚本
@ccclass
export default class PersonControl extends cc.Component {

    @property(cc.Node)
    dialog: cc.Node

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

    }

    start () {
        // this.setExpression(expressionMap.get('eye2'), expressionMap.get('mouth1'));
        // // 设置人名
        // this.dialog.getComponent(dialogControl).setPerson('炮姐');
        // // 设置话语
        // this.dialog.getComponent(dialogControl).setMessage('一二三四五')
    }

    // 设置表情
    setExpression(eye: string, mouth: string) {
        // 加载资源
        cc.resources.load('sprite/paojie', cc.SpriteAtlas,  (err, atlas)=> {
            let eyeFrame = atlas.getSpriteFrame(eye), mouthFrame = atlas.getSpriteFrame(mouth);
            this.node.children[0].getComponent(cc.Sprite).spriteFrame = eyeFrame;
            this.node.children[1].getComponent(cc.Sprite).spriteFrame = mouthFrame;
            
            // sprite.spriteFrame = frame;
        });
    }

    update (dt) {

    }
}
